﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IDAL;

namespace KPIS.GERP.GHRMS.DAL
{
    public sealed class MasMaritalStatusDAL : IMasMaritalStatusDAL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public MasMaritalStatusDAL()
        {

        }
        public IList<MasMaritalStatusInfo> ListMaritalStatus(MasMaritalStatusInfo msInfo)
        {
            string strSQL;

            List<MasMaritalStatusInfo> infoList = new List<MasMaritalStatusInfo>();

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@DeleteRecord", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@Sequence", msInfo.Sequence);

                strSQL = "SELECT *"
                   + " FROM MAS_MARITAL_STATUSES"
                   + " WHERE RECORD_STATUS not like @DeleteRecord"
                   + (msInfo.Sequence > 0 ? " AND MAR_STAT_SEQ = @Sequence" : "");

                IDataReader rdr = dbManager.ExecuteReader(CommandType.Text, strSQL);

                while (rdr.Read())
                {
                    MasMaritalStatusInfo Info = new MasMaritalStatusInfo(rdr.GetInt32(0)
                            , rdr.IsDBNull(1) ? "" : rdr.GetString(1));
                    infoList.Add(Info);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("{class MasMaritalStatusDAL}:" + ex.Message);
            }
            finally
            {
                dbManager.CloseReader();
                dbManager.Dispose();
            }
            return infoList;
        }
    }
}
